package com.cps.data.jpa.dao.support;

import com.cps.data.jpa.dao.BaseDao;
import com.cps.data.jpa.dao.BaseDaoImpl;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.core.RepositoryMetadata;

import javax.persistence.EntityManager;
import java.io.Serializable;

/**
 * Created by Jensen on 2016/9/28.
 */
public class BaseDaoFactory<T, ID extends Serializable> extends JpaRepositoryFactory {

    public BaseDaoFactory(EntityManager entityManager) {
        super(entityManager);
    }

    @SuppressWarnings({"rawtypes", "unchecked", "hiding"})
    @Override
    protected <T, ID extends Serializable> SimpleJpaRepository<?, ?> getTargetRepository(RepositoryInformation information, EntityManager entityManager) {
        // TODO Auto-generated method stub
        return new BaseDaoImpl(information.getDomainType(), entityManager);
    }


    @Override
    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
        // TODO Auto-generated method stub
        return BaseDao.class;
    }

}
